#include "CCaDisplayDescriptor.h"


CCaDisplayDescriptor::CCaDisplayDescriptor(void):IDescriptorData(DESCRIPTOR_TAG_CA_ADVERTISEMENT)
, m_wNetworkId(0xFFFF)    	
, m_wTsId(0xFFFF) 
, m_wServiceId(0xFFFF)
, m_dwLocationMask(0)
, m_ucGroupType(0)
, m_ucReserved(0)
, m_ucCaCardSize(0)
, m_strCardId("")
{	
	m_startTime = time (NULL);
	m_endTime = time(NULL);

}

CCaDisplayDescriptor::~CCaDisplayDescriptor(void)
{
}

void CCaDisplayDescriptor::GetData(BYTE* buff  , int &len)
{
	CBuffer stBuffer(buff, DESCRIPTOR_MAXLEN);

	PACK_DESCRIPTOR_BUFFER_START(stBuffer, DESCRIPTOR_TAG_CA_ADVERTISEMENT);
	
	BYTE aucTime[5] = {0, };
	ConvertTimeToUTC(m_startTime, aucTime);
	stBuffer.Write(aucTime, 5);
	memset(aucTime, 0xFF, sizeof(aucTime));
	ConvertTimeToUTC(m_endTime, aucTime);
	stBuffer.Write(aucTime, 5);

	stBuffer.Write(m_wNetworkId);
	stBuffer.Write(m_wTsId);
	stBuffer.Write(m_wServiceId);
	stBuffer.Write(m_dwLocationMask);

	stBuffer.Write(m_ucGroupType);

	stBuffer.Write(m_ucCaCardSize);
	stBuffer.Write((PBYTE)(m_strCardId.c_str()), (UINT)m_strCardId.size());

	stBuffer.Write(m_ucReserved);

	len = PACK_DESCRIPTOR_BUFFER_END(stBuffer);
}